﻿@model Citi.HeadCount.WebUI.Models.RuleResultViewModel
@{
    ViewBag.Title = "Create";
}
<script type="text/javascript">
    $(function () {
        $('#saveRuleResult').click(function () {
            var rulesTable = new Array(); ;

            $('#tableRules').find('tbody>tr').each(function (indexRow, valueRow) {
                if (indexRow > 0) {
                    var rulesItem = new Array(); ;

                    $($(this)[0].childNodes).each(function (index, value) {
                        var tdValue = $(value).html();
                        rulesItem.push(tdValue.substring(0, tdValue.length - 1));
                    });
                    rulesTable[indexRow - 1] = rulesItem;
                }
            });

            var postData = { rules: rulesTable, ruleResult: $('#formRuleResult').serialize() };
            
            $.ajax({
                type: "POST",
                url: '@Url.Action("Save", "RuleResult")',
                data: postData,
                success: function (data) {
                    alert(data.Result);
                },
                dataType: "json",
                traditional: true
            });
        });
    });
</script>
@using (Html.BeginForm("Save", "RuleResult", FormMethod.Post, new { id = "formRuleResult" }))
{
    <text>Rule Name: </text>
    @Html.TextBoxFor(model => model.Name, new { maxlength = 50 })
    @Html.Action("Create", "Rule")
    @Html.HiddenFor(model => model.Id, new { id = "RuleResultIdParent", name = "RuleResultIdParent" })
    <div id="rules">
        @Html.Action("Index", "Rule", new { ruleResultId = Model == null ? 0 : Model.Id })
    </div>
    <br />
    @Html.Action("Create", "TypeRuleResult")
    <div id="typeRules">
        @Html.Action("Index", "TypeRuleResult", new { ruleResultId = Model == null ? 0 : Model.Id })
    </div>
    <input type="button" id="saveRuleResult" value="Save" />
}